% Make Fitting Data For Real Data
clc;
clearvars

rng('shuffle');
tic
HumanDataFileName='Data\HumanData_KonovalovDataPart1.mat';
HumanDataFittingFile=[HumanDataFileName(1:end-4),'_FittingData_HF.mat'];
Methodes = {'Daw3ParamV1','Daw3ParamV2','Daw4Param','Daw5ParamV1','Daw5ParamV2','Daw6Param','Daw7ParamV1','Daw7ParamV2','Daw8Param'};
MethodesNum = length(Methodes);
%                   W   Alpha1  Alpha2  Beta1	Beta2	Lambda  P1  P2
ParamsIndex      = [1   1       0       1       0       0       0   0   %Daw3ParamV1
                    1   1       0       1       0       0       0   0   %Daw3ParamV2
                    1   1       0       1       0       1       0   0   %Daw4Param
                    1   1       1       1       1       0       0   0   %Daw5ParamV1
                    1   1       1       1       1       0       0   0   %Daw5ParamV2
                    1   1       1       1       1       1       0   0   %Daw6Param
                    1   1       1       1       1       1       1   0   %Daw7ParamV1
                    1   1       1       1       1       1       1   0   %Daw7ParamV2
                    1   1       1       1       1       1       1   1]; %Daw8Param
%                   W   Alpha1  Alpha2  Beta1	Beta2	Lambda  P1  P2
FittingParams.Low =[0   0       0       1       1       0       0   0];
FittingParams.High=[1   1       1       10      10      1       1   1];
FittingOption.StartNum=20;
FittingOption.MaxStep=300;

ObserveMat=load(HumanDataFileName);

fprintf('Fitting Observation\n')
SubjectNums=size(ObserveMat.ASARCMat,3);
BestFittedParams=zeros(SubjectNums,8,MethodesNum*2);
BestFittedNegLogLikelihood=zeros(SubjectNums,MethodesNum*2);
tic
Sofar=0;
Total=100*2*MethodesNum;
for M=1:MethodesNum
    ParamNum=sum(ParamsIndex(M,:));
    TempFittingParams=FittingParams;
    TempFittingParams.Low(ParamsIndex(M,:)==0)=[];
    TempFittingParams.High(ParamsIndex(M,:)==0)=[];
    [BestFittedParams(:,1:ParamNum,M            ),BestFittedNegLogLikelihood(:,M            )]=ParallDawNelderMeadFitting(ObserveMat,TempFittingParams,Methodes{M},'MLE',FittingOption.StartNum,FittingOption.MaxStep,[Methodes{M},'|MLE |'],Sofar,Total);
    Sofar=Sofar+FittingOption.MaxStep;
    [BestFittedParams(:,1:ParamNum,M+MethodesNum),BestFittedNegLogLikelihood(:,M+MethodesNum)]=ParallDawNelderMeadFitting(ObserveMat,TempFittingParams,Methodes{M},'MAP',FittingOption.StartNum,FittingOption.MaxStep,[Methodes{M},'|MAP |'],Sofar,Total);
    Sofar=Sofar+FittingOption.MaxStep;
end
toc
fprintf('Save Data\n')
save(HumanDataFittingFile,'BestFittedParams','BestFittedNegLogLikelihood','Methodes')
